package com.jiazixuan.stock.controller;

import com.jiazixuan.stock.pojo.domain.*;
import com.jiazixuan.stock.service.StockService;
import com.jiazixuan.stock.vo.resp.PageResult;
import com.jiazixuan.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 股票大盘相关接口处理器
 */
@Api(value = "/api/quot", tags = {"股票大盘相关接口处理器"})
@RestController
@RequestMapping("/api/quot")
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘最新的数据
     * @return
     */
    @ApiOperation(value = "获取国内大盘最新的数据", notes = "获取国内大盘最新的数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> innerIndexAll(){
        return stockService.innerIndexAll();
    }

    /**
     *获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
     * @return
     */
    @ApiOperation(value = "获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据", notes = "获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAll();
    }

    /**
     * 分页查询最新的股票交易数据
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "分页查询最新的股票交易数据", notes = "分页查询最新的股票交易数据", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockInfoByPage(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                                               @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockInfoByPage(page,pageSize);
    }

    /**
     * 查询最新股票交易前4条数据
     * @return
     */
    @ApiOperation(value = "查询最新股票交易前4条数据", notes = "查询最新股票交易前4条数据", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockInfoAnd4(){
        return stockService.getStockInfoAnd4();
    }

    /**
     * 统计最新股票交易日内每分钟的涨跌停的股票数量
     * @return
     */
    @ApiOperation(value = "统计最新股票交易日内每分钟的涨跌停的股票数量", notes = "统计最新股票交易日内每分钟的涨跌停的股票数量", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String,List>> getStockUpDownCount(){
        return stockService.getStockUpDownCount();
    }

    /**
     * 将指定页的股票数据导出到excel表下
     * @param response
     * @param page  当前页
     * @param pageSize 每页大小
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "将指定页的股票数据导出到excel表下", notes = "将指定页的股票数据导出到excel表下", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void stockExport(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                            @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize,
                            HttpServletResponse response){
        stockService.exportStockUpDownInfo(page,pageSize,response);
    }

    /**
     * 统计大盘股票T日和T-1日每分钟交易量的统计
     * @return
     */
    @ApiOperation(value = "统计大盘股票T日和T-1日每分钟交易量的统计", notes = "统计大盘股票T日和T-1日每分钟交易量的统计", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getComparedStockTradeAmt(){
        return stockService.getComparedStockTradeAmt();
    }

    /**
     * 个股涨跌
     * @return
     */
    @ApiOperation(value = "个股涨跌", notes = "个股涨跌", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map<String,Object>> getUpDown(){
        return stockService.getUpDown();
    }

    /**
     * 功能描述：查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据
     *          如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点
     * @param code 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "个股分时K线", notes = "功能描述：查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据          如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(@RequestParam(value = "code",required = true) String code){
        return stockService.stockScreenTimeSharing(code);
    }

    /**
     * 获取个股最新分时行情数据
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "获取个股最新分时行情数据", notes = "获取个股最新分时行情数据", httpMethod = "GET")
    @GetMapping("/stock/screen/second/detail")
    public R<StockNewMinuteDomain> getStockNew(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockNew(code);
    }

    /**
     * 查询最新交易流水
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "查询最新交易流水", notes = "查询最新交易流水", httpMethod = "GET")
    @GetMapping("/stock/screen/second")
    public R<List<StockTransactionFlow>> getStockTransactionFlow(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockTransactionFlow(code);
    }

    /**
     * 查询指定股票每天产生的数据，组装成日K线数据
     * @param code 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "日K线数据", notes = "查询指定股票每天产生的数据，组装成日K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> stockScreenTimeDay(@RequestParam(value = "code",required = true) String code){
        return stockService.stockScreenTimeDay(code);
    }
    /**
     * 外盘指数行情数据查询，根据时间和大盘点数降序排序取前4
     */
    @ApiOperation(value = "外盘指数行情数据查询", notes = "外盘指数行情数据查询，根据时间和大盘点数降序排序取前4", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> outerMarket(){
        return stockService.outerMarket();
    }

    /**
     * 搜索框模糊查询
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "searchStr", value = "", required = true)
    })
    @ApiOperation(value = "搜索框模糊查询", notes = "搜索框模糊查询", httpMethod = "GET")
    @GetMapping("/stock/search")
    public R<List<Map>> searchStock(@RequestParam(value = "searchStr",required = true) String searchStr){
        return stockService.searchStock(searchStr);
    }

    /**
     * 周K
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "周K", notes = "周K", httpMethod = "GET")
    @GetMapping("/stock/screen/weekkline")
    public R<List<Stock4EvrWeekDomain>> getWeekStock(@RequestParam(value = "code",required = true) String code){
        return stockService.getWeekStock(code);
    }

    /**
     * 个股主营业务
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "个股主营业务", notes = "个股主营业务", httpMethod = "GET")
    @GetMapping("/stock/describe")
    public R<StockBusinessInfomation> getInfomation(@RequestParam(value = "code",required = true) String code){
        return stockService.getInfomation(code);
    }
}
